package com.example.springbootvalidated.controller;
import com.example.springbootvalidated.entity.User;
import com.example.springbootvalidated.service.UserService;
import com.example.springbootvalidated.utils.ResultReturn;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * Created by IntelliJ IDEA2022.3.2
 * @Author: Tenghw
 * @Date: 2023/05/05  15:53
 * @Description:
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    @PostMapping ("/addUser")
    public ResultReturn addUser(@RequestBody @Validated User user) {
        user.setId(null);
        log.info("新增用户为{}",user);
        return userService.addUser(user);
    }
}
